package com.basic.business.smb.controller;


import java.util.List;
import java.io.IOException;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import com.basic.common.annotation.FileExport;
import com.basic.common.utils.easyExcel.EasyExcelUtils;
import org.springframework.web.bind.annotation.*;
import com.basic.common.annotation.Log;
import com.basic.common.core.controller.BaseController;
import com.basic.common.core.domain.AjaxResult;
import com.basic.common.enums.BusinessType;
import com.basic.business.smb.domain.TSmbMgmt;
import com.basic.business.smb.service.ITSmbMgmtService;
import com.basic.common.core.page.TableDataInfo;

/**
 * SMB管理Controller
 * 
 * @author zhaoxy_jn@163.com
 */
@RestController
@RequestMapping("/business/smbMgmt")
public class TSmbMgmtController extends BaseController
{
    @Resource
    private ITSmbMgmtService tSmbMgmtService;

    /**
     * 查询SMB管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSmbMgmt tSmbMgmt)
    {
        startPage();
        List<TSmbMgmt> list = tSmbMgmtService.getList(tSmbMgmt);
        return getDataTable(list);
    }

    /**
     * 导出SMB管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:export')")
    @Log(title = "SMB管理", businessType = BusinessType.EXPORT)
    @FileExport(fileName = "SMB管理.xlsx")
    @PostMapping("/export")
    public String export(TSmbMgmt tSmbMgmt) throws IOException
    {
        List<TSmbMgmt> list = tSmbMgmtService.getList(tSmbMgmt);
        return EasyExcelUtils.excelExport(TSmbMgmt.class,"SMB管理数据", list);
    }

    /**
     * 获取SMB管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tSmbMgmtService.get(id));
    }

    /**
     * 新增SMB管理
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:add')")
    @Log(title = "SMB管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSmbMgmt tSmbMgmt)
    {
        return toAjax(tSmbMgmtService.insert(tSmbMgmt));
    }

    /**
     * 修改SMB管理
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:edit')")
    @Log(title = "SMB管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSmbMgmt tSmbMgmt)
    {
        return toAjax(tSmbMgmtService.update(tSmbMgmt));
    }

    /**
     * 删除SMB管理
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:remove')")
    @Log(title = "SMB管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tSmbMgmtService.deleteByIds(ids));
    }

    /**
     * 测试连接
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:testConnection')")
    @Log(title = "SMB管理", businessType = BusinessType.OTHER)
    @PostMapping("/testConnection")
    public AjaxResult testConnection(@RequestBody TSmbMgmt tSmbMgmt)
    {
        return success(tSmbMgmtService.testConnection(tSmbMgmt));
    }

    /**
     * 状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:changeStatus')")
    @Log(title = "SMB管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tSmbMgmtService.updateStatusByIds(ids, status));
    }

    /**
     * 挂载状态变更
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:changeMountStatus')")
    @Log(title = "SMB管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeMountStatus")
    public AjaxResult changeMountStatus(@RequestParam("ids") String[] ids, @RequestParam("status") String status)
    {
        return toAjax(tSmbMgmtService.updateMountStatusByIds(ids, status));
    }

    /**
     * 查询是否存在已挂载的SMB
     */
    @GetMapping("/isExistMountSMB")
    public AjaxResult isExistMountSMB()
    {
        return AjaxResult.success(tSmbMgmtService.isExistMountSMB());
    }

    /**
     * 刷新缓存
     */
    @PreAuthorize("@ss.hasPermi('business:smbMgmt:refreshCache')")
    @Log(title = "SMB管理", businessType = BusinessType.CLEAN)
    @DeleteMapping("/refreshCache")
    public AjaxResult refreshCache()
    {
        tSmbMgmtService.resetSmbCache();
        return success();
    }

}
